package cn.kgc.psringboot.service.impl;

import cn.kgc.psringboot.util.SaltUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.psringboot.entity.User;
import cn.kgc.psringboot.service.UserService;
import cn.kgc.psringboot.mapper.UserMapper;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService{

    @Autowired(required = false)
    private UserMapper userMapper;
    @Override
    public Boolean saveUser(User user) {
        //获取随机盐
        String salt = SaltUtil.getSalt(6);
        user.setSalt(salt);
        Md5Hash md5Password = new Md5Hash(user.getPassword(),salt,1024);
        user.setPassword(md5Password.toHex());
        int line = userMapper.insert(user);
        return line==1;
    }
}




